Assigning report datasets at runtime
Is it possible to assign TDataset for a report at runtime?
My issue:
I have designed a report using some mem-datasets connected to frxDBDatasets, both design time components.
The report is saved to a file.
In another application I will load this report, but without the design time datasets and frxDBDatasets.
These I would create at runtime an assign to the report.
frxDBDataset := TfrxDBDataset.Create(TheReport);
frxDBDataset.Name := 'fxdbEmployee'; // Same name as at design-time
frxDBDataset.UserName := 'Employee'; // Same name as at design-time
frxDBDataset.DataSet := TheDataset; // EmployeeDS, same name as at design-time
TheReport.DataSets[0].DataSetName; // = "Employee";
TheReport.ShowReport();
When I do this I get a message box saying "Dataset "Employee" does not exist".
Do anyone who knows have to do this?
Thanks
My issue:
I have designed a report using some mem-datasets connected to frxDBDatasets, both design time components.
The report is saved to a file.
In another application I will load this report, but without the design time datasets and frxDBDatasets.
These I would create at runtime an assign to the report.
frxDBDataset := TfrxDBDataset.Create(TheReport);
frxDBDataset.Name := 'fxdbEmployee'; // Same name as at design-time
frxDBDataset.UserName := 'Employee'; // Same name as at design-time
frxDBDataset.DataSet := TheDataset; // EmployeeDS, same name as at design-time
TheReport.DataSets[0].DataSetName; // = "Employee";
TheReport.ShowReport();
When I do this I get a message box saying "Dataset "Employee" does not exist".
Do anyone who knows have to do this?
Thanks
Comments
I do similar like you've done but I not create frxDataset at runtime,
I use Memory table too...may be you just need to load dataset properly !
this my delphi code [img]style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> var md,kode,wtime,anything: TfrxComponent; //include fastreport unit files first on your uses begin if fileexists(appPath + '\frpt\Log.fr3') then frxReport1.LoadFromFile(appPath + '\frpt\Log.fr3') else begin Messagedialog('Report not found..!', mterror, [mbOk], 0); exit; end; //[/img]
this is to add dataset from frxDataset
//
at design time or may at runtime I don't know.. try your self
frxReport1.DataSets.Add(frxDBDataset1);
frxReport1.EnabledDataSets.Add(frxDBDataset1);
//----databand Masterdata1
md := frxReport1.FindObject('Masterdata1'); //point to Masterdata1 at Page1 of report file
(md as Tfrxmasterdata).DataSet := frxDBdataset1;
(md as Tfrxmasterdata).DataSetName := 'Masterdata1';
//--- fields of masterData1
wtime := frxReport1.FindObject('frxDbdataset1Name'); //this unique name "frxDbdataset1Name" I use for tfrxMemo at Page of report file
(wtime as TfrxMemoview).DataSet := frxDBdataset1;
(wtime as TfrxMemoview).DataSetName := 'waktu';
(wtime as TfrxMemoview).DataField := 'waktu';
kode := frxReport1.FindObject('frxDbdataset1Name1'); //this unique name "frxDbdataset1Name1" I use for tfrxMemo at Page of report file
//I read this technique in this forum too but I don't remember where is
(kode as TfrxMemoview).DataSet := frxDBdataset1;
(kode as TfrxMemoview).DataSetName := 'kode';
(kode as TfrxMemoview).DataField := 'kode';
anything := frxReport1.FindObject('frxDbdataset1Name2'); //this unique name "frxDbdataset1Name2" I use for tfrxMemo at Page of report file
(anything as TfrxMemoview).DataSet := frxDBdataset1;
(anything as TfrxMemoview).DataSetName := 'any';
(anything as TfrxMemoview).DataField := 'any';
//---preview the report---
frxreport1.ShowReport(true);
//---just type this...
frxDbdataset1.DataSet := nil;
frxReport1.Clear;
end;
regards,